<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>检测变量是否是一个标量</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.is-resource.html">« is_resource</a></li>
      <li style="float: right;"><a href="function.is-string.html">is_string »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.var.html">Variable handling 函数</a></li>
    <li>检测变量是否是一个标量</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.is-scalar" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">is_scalar</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.5, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">is_scalar</span> &mdash; <span class="dc-title">
     检测变量是否是一个标量
  </span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.is-scalar-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>is_scalar</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span> <code class="parameter">$value</code></span>): <span class="type">bool</span></div>

  <p class="para rdfs-comment">
   检测变量是否为标量
  </p>
  <p class="para">
   标量变量是指 <span class="type">int</span>、<span class="type">float</span>、<span class="type">string</span> 或 <span class="type">bool</span> 类型的变量。
   <span class="type">array</span>、<span class="type">object</span> 、 <span class="type">resource</span> 和 <span class="type">null</span> 类型不是标量。
  </p>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    <span class="function"><strong>is_scalar()</strong></span> 不会将 <span class="type">resource</span> 类型值视为标量，
    因为当前 resources 是基于整数（integer）的抽象数据类型。
    不能依赖该执行细节，因为它可能会改变。
   </p>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    <span class="function"><strong>is_scalar()</strong></span> 不会将 NULL 检测为标量。
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.is-scalar-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">value</code></dt>

     <dd>

      <p class="para">
       需要检测的变量。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.is-scalar-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   如果 <code class="parameter">value</code> 是标量，则返回 <strong><code>true</code></strong> ，否则返回 <strong><code>false</code></strong> 。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.is-scalar-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-5294">
    <p><strong>示例 #1 <span class="function"><strong>is_scalar()</strong></span> 示例</strong></p>
    <div class="example-contents">

<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">show_var</span><span style="color: #007700">(</span><span style="color: #0000BB">$var</span><span style="color: #007700">)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(</span><span style="color: #0000BB">is_scalar</span><span style="color: #007700">(</span><span style="color: #0000BB">$var</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$var</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$var</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /></span><span style="color: #0000BB">$pi&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">3.1416</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$proteins&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">"hemoglobin"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"cytochrome&nbsp;c&nbsp;oxidase"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"ferredoxin"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">show_var</span><span style="color: #007700">(</span><span style="color: #0000BB">$pi</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">show_var</span><span style="color: #007700">(</span><span style="color: #0000BB">$proteins</span><span style="color: #007700">)<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
3.1416
array(3) {
  [0]=&gt;
  string(10) &quot;hemoglobin&quot;
  [1]=&gt;
  string(20) &quot;cytochrome c oxidase&quot;
  [2]=&gt;
  string(10) &quot;ferredoxin&quot;
}
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.is-scalar-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.is-float.html" class="function" rel="rdfs-seeAlso">is_float()</a> - 查找变量的类型是否是浮点型</span></li>
    <li class="member"><span class="function"><a href="function.is-int.html" class="function" rel="rdfs-seeAlso">is_int()</a> - 检测变量是否是整数</span></li>
    <li class="member"><span class="function"><a href="function.is-numeric.html" class="function" rel="rdfs-seeAlso">is_numeric()</a> - 检测变量是否为数字或数字字符串</span></li>
    <li class="member"><span class="function"><a href="function.is-real.html" class="function" rel="rdfs-seeAlso">is_real()</a> - 别名 is_float</span></li>
    <li class="member"><span class="function"><a href="function.is-string.html" class="function" rel="rdfs-seeAlso">is_string()</a> - 查找变量的类型是否是字符串</span></li>
    <li class="member"><span class="function"><a href="function.is-bool.html" class="function" rel="rdfs-seeAlso">is_bool()</a> - 检测变量是否是布尔值</span></li>
    <li class="member"><span class="function"><a href="function.is-object.html" class="function" rel="rdfs-seeAlso">is_object()</a> - 查找变量是否是字符串</span></li>
    <li class="member"><span class="function"><a href="function.is-array.html" class="function" rel="rdfs-seeAlso">is_array()</a> - 检测变量是否是数组</span></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>